package com.cfets.annualAssessment.service;

import com.cfets.annualAssessment.entity.SMSBlack;
import com.cfets.annualAssessment.mapper.SMSBlackMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by ShenYiChou on 2017/2/3.
 */
@Service
public class SMSBlackService {
    @Autowired
    private SMSBlackMapper smsBlackMapper;

    public List<SMSBlack> getSMSBlackPage(SMSBlack smsBlack) {
        Page<?> page = PageHelper.startPage(smsBlack.getPage(), smsBlack.getRows(), "id");
        List<SMSBlack> smsBlacks=null;
        smsBlacks = this.getSMSBlack(smsBlack);
        smsBlack.setTotalCount(page.getTotal());
        return smsBlacks;
    }

    public boolean newSMSBlack(SMSBlack smsBlack) {
        return smsBlackMapper.insertSelective(smsBlack)>0;
    }

//    public boolean updateSMSBlack(SMSBlack smsBlack) {
//        return smsBlackMapper.updateByPrimaryKey(smsBlack)>0;
//    }

    public boolean deleteSMSBlackById(int id) {
        return smsBlackMapper.deleteByPrimaryKey(id)>0;
    }

    public List<SMSBlack> getSMSBlack(SMSBlack smsBlack){
        Example example=new Example(SMSBlack.class);
        Example.Criteria criteria =example.createCriteria();
        if(!StringUtils.isEmpty(smsBlack.getMobile())){
            criteria.andEqualTo("mobile",smsBlack.getMobile());
        }
        if(!StringUtils.isEmpty(smsBlack.getName())){
            criteria.andLike("name","%"+smsBlack.getName()+"%");
        }
        return smsBlackMapper.selectByExample(example);
    }
}
